@ibiz-template-plugin/ibiz-file-previewer 0.0.25 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -917,6 +917,8 @@ var ImageMode = /* @__PURE__ */ ((ImageMode2) => {
917
917
  var FileType = /* @__PURE__ */ ((FileType2) => {
918
918
  FileType2["HTML"] = "html";
919
919
  FileType2["MD"] = "md";
920
+ FileType2["YAML"] = "yaml";
921
+ FileType2["YML"] = "yml";
920
922
  FileType2["TXT"] = "txt";
921
923
  FileType2["JSON"] = "json";
922
924
  FileType2["XML"] = "xml";
@@ -940,6 +942,10 @@ var FileType = /* @__PURE__ */ ((FileType2) => {
940
942
  FileType2["JPEG"] = "jpeg";
941
943
  FileType2["ICO"] = "ico";
942
944
  FileType2["CSV"] = "csv";
945
+ FileType2["VUE"] = "vue";
946
+ FileType2["TSV"] = "tsv";
947
+ FileType2["MP4"] = "mp4";
948
+ FileType2["PHP"] = "php";
943
949
  FileType2["UNKNOWN"] = "UNKNOWN";
944
950
  return FileType2;
945
951
  })(FileType || {});
@@ -984,24 +990,47 @@ const FileTypeEngineMap = /* @__PURE__ */ new Map([
984
990
  ]],
985
991
  // ET类型文件
986
992
  // ------TXT类型文件服务端暂未支持START------
987
- // [FileType.TXT, [EngineType.TXT]], // TXT类型文件
988
- // [FileType.JSON, [EngineType.TXT]], // JSON类型文件
989
- // [FileType.XML, [EngineType.TXT]], // XML类型文件
990
- ["txt", [
991
- "MD"
992
- /* MD */
993
+ ["yaml", [
994
+ "TXT"
995
+ /* TXT */
993
996
  ]],
994
- // TXT类型文件
997
+ // YAML类型文件
998
+ ["yml", [
999
+ "TXT"
1000
+ /* TXT */
1001
+ ]],
1002
+ // YML类型文件
995
1003
  ["json", [
996
- "MD"
997
- /* MD */
1004
+ "TXT"
1005
+ /* TXT */
998
1006
  ]],
999
1007
  // JSON类型文件
1000
1008
  ["xml", [
1009
+ "TXT"
1010
+ /* TXT */
1011
+ ]],
1012
+ // XML类型文件
1013
+ ["vue", [
1014
+ "TXT"
1015
+ /* TXT */
1016
+ ]],
1017
+ // VUE类型文件
1018
+ ["tsv", [
1019
+ "TXT"
1020
+ /* TXT */
1021
+ ]],
1022
+ // TSV类型文件
1023
+ ["php", [
1024
+ "TXT"
1025
+ /* TXT */
1026
+ ]],
1027
+ // PHP类型文件
1028
+ // [FileType.TXT, [EngineType.TXT]], // TXT类型文件
1029
+ ["txt", [
1001
1030
  "MD"
1002
1031
  /* MD */
1003
1032
  ]],
1004
- // XML类型文件
1033
+ // TXT类型文件
1005
1034
  // ------TXT类型文件服务端暂未支持END------
1006
1035
  ["pdf", [
1007
1036
  "PDF"
@@ -1079,8 +1108,13 @@ const FileTypeEngineMap = /* @__PURE__ */ new Map([
1079
1108
  ["ico", [
1080
1109
  "IMG"
1081
1110
  /* IMG */
1082
- ]]
1111
+ ]],
1083
1112
  // ICO类型文件
1113
+ ["mp4", [
1114
+ "IMG"
1115
+ /* IMG */
1116
+ ]]
1117
+ // MP4类型文件
1084
1118
  ]);
1085
1119
  const contentWidth = 800;
1086
1120
  const imgModes = [
@@ -1163,6 +1197,9 @@ const fileNameToFileType = (fileName) => {
1163
1197
  case "svg":
1164
1198
  fileType = FileType.SVG;
1165
1199
  break;
1200
+ case "mp4":
1201
+ fileType = FileType.MP4;
1202
+ break;
1166
1203
  case "bmp":
1167
1204
  fileType = FileType.BMP;
1168
1205
  break;
@@ -1178,6 +1215,21 @@ const fileNameToFileType = (fileName) => {
1178
1215
  case "csv":
1179
1216
  fileType = FileType.CSV;
1180
1217
  break;
1218
+ case "yaml":
1219
+ fileType = FileType.YAML;
1220
+ break;
1221
+ case "yml":
1222
+ fileType = FileType.YML;
1223
+ break;
1224
+ case "vue":
1225
+ fileType = FileType.VUE;
1226
+ break;
1227
+ case "tsv":
1228
+ fileType = FileType.TSV;
1229
+ break;
1230
+ case "php":
1231
+ fileType = FileType.PHP;
1232
+ break;
1181
1233
  default:
1182
1234
  fileType = FileType.UNKNOWN;
1183
1235
  }
@@ -1241,6 +1293,9 @@ const copyTextToClipboard = async (text) => {
1241
1293
  return fallbackCopyTextToClipboard(text);
1242
1294
  }
1243
1295
  };
1296
+ const isObject = (obj) => {
1297
+ return toString.call(obj) === "[object Object]";
1298
+ };
1244
1299
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
1245
1300
  function getDefaultExportFromCjs(x2) {
1246
1301
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
@@ -2268,18 +2323,38 @@ const FilePreviewImage = (props) => {
2268
2323
  if (controller.state.value.fileType === FileType.SVG)
2269
2324
  props.onInitialization();
2270
2325
  }, []);
2271
- return /* @__PURE__ */ u("div", { className: "file-preview-image ".concat(controller.state.value.theme), children: [
2272
- controller.state.value.fileType === FileType.SVG ? /* @__PURE__ */ u(
2273
- "div",
2274
- {
2275
- className: "svg-container",
2276
- style: imgStyle.value,
2277
- dangerouslySetInnerHTML: {
2278
- __html: controller.state.value.content
2279
- },
2280
- onMouseDown: (evt) => controller.handleMouseDown(evt)
2281
- }
2282
- ) : /* @__PURE__ */ u(
2326
+ const renderContent = () => {
2327
+ if (controller.state.value.fileType === FileType.SVG) {
2328
+ return /* @__PURE__ */ u(
2329
+ "div",
2330
+ {
2331
+ className: "svg-container",
2332
+ style: imgStyle.value,
2333
+ dangerouslySetInnerHTML: {
2334
+ __html: controller.state.value.content
2335
+ },
2336
+ onMouseDown: (evt) => controller.handleMouseDown(evt)
2337
+ }
2338
+ );
2339
+ }
2340
+ if (controller.state.value.fileType === FileType.MP4) {
2341
+ return /* @__PURE__ */ u(
2342
+ "video",
2343
+ {
2344
+ controls: true,
2345
+ onLoadedData: () => props.onInitialization(),
2346
+ onError: () => props.onInitialization(),
2347
+ children: /* @__PURE__ */ u(
2348
+ "source",
2349
+ {
2350
+ src: controller.state.value.content,
2351
+ type: "video/mp4"
2352
+ }
2353
+ )
2354
+ }
2355
+ );
2356
+ }
2357
+ return /* @__PURE__ */ u(
2283
2358
  "img",
2284
2359
  {
2285
2360
  style: imgStyle.value,
@@ -2288,7 +2363,10 @@ const FilePreviewImage = (props) => {
2288
2363
  onError: () => props.onInitialization(),
2289
2364
  onMouseDown: (evt) => controller.handleMouseDown(evt)
2290
2365
  }
2291
- ),
2366
+ );
2367
+ };
2368
+ return /* @__PURE__ */ u("div", { className: "file-preview-image ".concat(controller.state.value.theme), children: [
2369
+ renderContent(),
2292
2370
  /* @__PURE__ */ u(Teleport, { to: "#".concat(controller.controlsId), children: /* @__PURE__ */ u("div", { className: "image-toolbar-container", children: [
2293
2371
  /* @__PURE__ */ u(
2294
2372
  "button",
@@ -18789,14 +18867,228 @@ function xml(hljs) {
18789
18867
  ]
18790
18868
  };
18791
18869
  }
18870
+ function yaml(hljs) {
18871
+ const LITERALS = "true false yes no null";
18872
+ const URI_CHARACTERS = "[\\w#;/?:@&=+$,.~*'()[\\]]+";
18873
+ const KEY = {
18874
+ className: "attr",
18875
+ variants: [
18876
+ // added brackets support and special char support
18877
+ { begin: /[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/ },
18878
+ {
18879
+ // double quoted keys - with brackets and special char support
18880
+ begin: /"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/
18881
+ },
18882
+ {
18883
+ // single quoted keys - with brackets and special char support
18884
+ begin: /'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/
18885
+ }
18886
+ ]
18887
+ };
18888
+ const TEMPLATE_VARIABLES = {
18889
+ className: "template-variable",
18890
+ variants: [
18891
+ {
18892
+ // jinja templates Ansible
18893
+ begin: /\{\{/,
18894
+ end: /\}\}/
18895
+ },
18896
+ {
18897
+ // Ruby i18n
18898
+ begin: /%\{/,
18899
+ end: /\}/
18900
+ }
18901
+ ]
18902
+ };
18903
+ const SINGLE_QUOTE_STRING = {
18904
+ className: "string",
18905
+ relevance: 0,
18906
+ begin: /'/,
18907
+ end: /'/,
18908
+ contains: [
18909
+ {
18910
+ match: /''/,
18911
+ scope: "char.escape",
18912
+ relevance: 0
18913
+ }
18914
+ ]
18915
+ };
18916
+ const STRING = {
18917
+ className: "string",
18918
+ relevance: 0,
18919
+ variants: [
18920
+ {
18921
+ begin: /"/,
18922
+ end: /"/
18923
+ },
18924
+ { begin: /\S+/ }
18925
+ ],
18926
+ contains: [
18927
+ hljs.BACKSLASH_ESCAPE,
18928
+ TEMPLATE_VARIABLES
18929
+ ]
18930
+ };
18931
+ const CONTAINER_STRING = hljs.inherit(STRING, { variants: [
18932
+ {
18933
+ begin: /'/,
18934
+ end: /'/,
18935
+ contains: [
18936
+ {
18937
+ begin: /''/,
18938
+ relevance: 0
18939
+ }
18940
+ ]
18941
+ },
18942
+ {
18943
+ begin: /"/,
18944
+ end: /"/
18945
+ },
18946
+ { begin: /[^\s,{}[\]]+/ }
18947
+ ] });
18948
+ const DATE_RE = "[0-9]{4}(-[0-9][0-9]){0,2}";
18949
+ const TIME_RE = "([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?";
18950
+ const FRACTION_RE = "(\\.[0-9]*)?";
18951
+ const ZONE_RE = "([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?";
18952
+ const TIMESTAMP = {
18953
+ className: "number",
18954
+ begin: "\\b" + DATE_RE + TIME_RE + FRACTION_RE + ZONE_RE + "\\b"
18955
+ };
18956
+ const VALUE_CONTAINER = {
18957
+ end: ",",
18958
+ endsWithParent: true,
18959
+ excludeEnd: true,
18960
+ keywords: LITERALS,
18961
+ relevance: 0
18962
+ };
18963
+ const OBJECT = {
18964
+ begin: /\{/,
18965
+ end: /\}/,
18966
+ contains: [VALUE_CONTAINER],
18967
+ illegal: "\\n",
18968
+ relevance: 0
18969
+ };
18970
+ const ARRAY = {
18971
+ begin: "\\[",
18972
+ end: "\\]",
18973
+ contains: [VALUE_CONTAINER],
18974
+ illegal: "\\n",
18975
+ relevance: 0
18976
+ };
18977
+ const MODES2 = [
18978
+ KEY,
18979
+ {
18980
+ className: "meta",
18981
+ begin: "^---\\s*$",
18982
+ relevance: 10
18983
+ },
18984
+ {
18985
+ // multi line string
18986
+ // Blocks start with a | or > followed by a newline
18987
+ //
18988
+ // Indentation of subsequent lines must be the same to
18989
+ // be considered part of the block
18990
+ className: "string",
18991
+ begin: "[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*"
18992
+ },
18993
+ {
18994
+ // Ruby/Rails erb
18995
+ begin: "<%[%=-]?",
18996
+ end: "[%-]?%>",
18997
+ subLanguage: "ruby",
18998
+ excludeBegin: true,
18999
+ excludeEnd: true,
19000
+ relevance: 0
19001
+ },
19002
+ {
19003
+ // named tags
19004
+ className: "type",
19005
+ begin: "!\\w+!" + URI_CHARACTERS
19006
+ },
19007
+ // https://yaml.org/spec/1.2/spec.html#id2784064
19008
+ {
19009
+ // verbatim tags
19010
+ className: "type",
19011
+ begin: "!<" + URI_CHARACTERS + ">"
19012
+ },
19013
+ {
19014
+ // primary tags
19015
+ className: "type",
19016
+ begin: "!" + URI_CHARACTERS
19017
+ },
19018
+ {
19019
+ // secondary tags
19020
+ className: "type",
19021
+ begin: "!!" + URI_CHARACTERS
19022
+ },
19023
+ {
19024
+ // fragment id &ref
19025
+ className: "meta",
19026
+ begin: "&" + hljs.UNDERSCORE_IDENT_RE + "$"
19027
+ },
19028
+ {
19029
+ // fragment reference *ref
19030
+ className: "meta",
19031
+ begin: "\\*" + hljs.UNDERSCORE_IDENT_RE + "$"
19032
+ },
19033
+ {
19034
+ // array listing
19035
+ className: "bullet",
19036
+ // TODO: remove |$ hack when we have proper look-ahead support
19037
+ begin: "-(?=[ ]|$)",
19038
+ relevance: 0
19039
+ },
19040
+ hljs.HASH_COMMENT_MODE,
19041
+ {
19042
+ beginKeywords: LITERALS,
19043
+ keywords: { literal: LITERALS }
19044
+ },
19045
+ TIMESTAMP,
19046
+ // numbers are any valid C-style number that
19047
+ // sit isolated from other words
19048
+ {
19049
+ className: "number",
19050
+ begin: hljs.C_NUMBER_RE + "\\b",
19051
+ relevance: 0
19052
+ },
19053
+ OBJECT,
19054
+ ARRAY,
19055
+ SINGLE_QUOTE_STRING,
19056
+ STRING
19057
+ ];
19058
+ const VALUE_MODES = [...MODES2];
19059
+ VALUE_MODES.pop();
19060
+ VALUE_MODES.push(CONTAINER_STRING);
19061
+ VALUE_CONTAINER.contains = VALUE_MODES;
19062
+ return {
19063
+ name: "YAML",
19064
+ case_insensitive: true,
19065
+ aliases: ["yml"],
19066
+ contains: MODES2
19067
+ };
19068
+ }
18792
19069
  HighlightJS.registerLanguage("xml", xml);
18793
19070
  HighlightJS.registerLanguage("json", json);
19071
+ HighlightJS.registerLanguage("yaml", yaml);
18794
19072
  const FilePreviewText = (props) => {
18795
19073
  const c2 = props.controller;
18796
19074
  const previewRef = A(null);
18797
19075
  y$1(() => {
18798
19076
  try {
18799
- previewRef.current.textContent = c2.state.value.content;
19077
+ if (c2.state.value.fileType === FileType.JSON) {
19078
+ try {
19079
+ let jsonObject;
19080
+ if (isObject(c2.state.value.content) || Array.isArray(c2.state.value.content)) {
19081
+ jsonObject = c2.state.value.content;
19082
+ } else {
19083
+ jsonObject = JSON.parse(c2.state.value.content);
19084
+ }
19085
+ previewRef.current.textContent = JSON.stringify(jsonObject, null, 2);
19086
+ } catch (error2) {
19087
+ previewRef.current.textContent = c2.state.value.content;
19088
+ }
19089
+ } else {
19090
+ previewRef.current.textContent = c2.state.value.content;
19091
+ }
18800
19092
  HighlightJS.highlightElement(previewRef.current);
18801
19093
  } catch (error2) {
18802
19094
  console.error(error2);